package com.dllo.lanou.cookapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dllo.lanou.cookapp.R;
import com.dllo.lanou.cookapp.entity.BookListEntity;
import com.dllo.lanou.cookapp.entity.CookClassifyEntity;
import com.dllo.lanou.cookapp.volly.GetVolleyImage;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xijinhua on 2016/3/28.
 */
public class ClassifyNameAdapter  extends BaseAdapter {
    private List<CookClassifyEntity.ClassifyEntity> classifyEntities;
    private Context context;
    private LayoutInflater mInflater;

    public ClassifyNameAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    public void addDatas(List<CookClassifyEntity.ClassifyEntity> classifyEntities) {
        this.classifyEntities = classifyEntities;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return classifyEntities != null && classifyEntities.size() > 0
                ? classifyEntities.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return classifyEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_classify, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();

        }

        CookClassifyEntity.ClassifyEntity classifyEntity = classifyEntities.get(position);
        holder.class_name.setText(classifyEntity.getName());
//        if (bookListEntity.getImg() != null){
//            String url = "http://tnfs.tngou.net/image"+ bookListEntity.getImg();
//            GetVolleyImage.getNetWorkImg(url, holder.book_img);
//        }

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.class_name)
        TextView class_name;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}